package app.productmanagement.web.ProductTag.controller;

import app.productmanagement.Pojo.Result;
import app.productmanagement.web.ProductAndTag.Service.impl.ProductTagServiceInterface;
import app.productmanagement.web.ProductTag.Pojo.TagRequest;
import app.productmanagement.web.ProductTag.Pojo.tagLimitVo;
import app.productmanagement.web.ProductTag.service.impl.TagServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/tag")
@RequiredArgsConstructor
public class TagController {

    private final TagServiceInterface tagService;

    private final ProductTagServiceInterface productTagServiceInterface;

    // 分页查询获取所有标签
    @GetMapping
    public Result<?> getAllTags(@RequestParam( required = false, defaultValue = "1") int page,
                                @RequestParam( required = false, defaultValue = "10") int limit) {
        return tagService.getAllTags(page, limit);
    }


    // 创建新标签
    @PostMapping
    public Result<?> createTag(@RequestBody TagRequest tagRequest) {
        return tagService.addTag(tagRequest);
    }

    // 更新标签信息
    @PutMapping("/{id}")
    public Result<?> updateTag(@PathVariable int id, @RequestBody TagRequest tagRequest) {
        return tagService.updateTag(id, tagRequest);
    }

    // 删除标签
    @DeleteMapping("/{id}")
    public Result<?> deleteTag(@PathVariable int id) {
        // 需要删除 ProductTag 链接表的内容
        productTagServiceInterface.deleteProductTags(false, id);

        return  tagService.deleteTag(id);
    }


}